{js:my97date}
{set:$seller_id = $this->seller['seller_id']}
{set:$id = $_GET['id']}
<script type='text/javascript' src="{theme:javascript/ajaxfileupload.js}"></script>
<article class="module width_full">
    <header>
        <h3 class="tabs_involved"> 编辑优惠券</h3>
    </header>
    <form action='{url:/sellercoupon/coupon_update}' method='post' >
        <input type="hidden" name="coupon_id" id="coupon_id" value="{$id}"/>
        <div class="module_content">
            <fieldset>
                <label>使用渠道：</label>
                <select  class="auto">
                    <option value="1">线上使用</option>
                </select>
            </fieldset>
            <fieldset>
                <label>优惠券类型：</label>
                <input  value="1" type="radio" checked="checked">抵用券
            </fieldset>
            <fieldset>
                <label>优惠券名称:</label>
                <input  class="large" name="coupon_name" type="text"   readonly value="{$info['name']}" />
            </fieldset>
            <fieldset>
                <label>使用范围:</label>
                {if:$goods_info}
                <table id="speed_goods" class="td_c">
                    <td>{$goods_info['name']}</td>
                    <td>价格：{$goods_info['sell_price']}</td>
                    <td>积分：{$goods_info['pay_point']}</td>
                    <td>库存：{$goods_info['store_nums']}</td>
                </table>
                {/if}
            </fieldset>
            <fieldset>
                <label>优惠额度:</label>
                {if:$info['use_type']==1}
                <input  name="discount_money" class="normal"   disabled="disabled"  type="text" value="{$info['discount_money']}"/><label class="tip">*元</label>
                {else:}
                <input  name="discount_point" class="normal"   disabled="disabled"  type="text" value="{$info['discount_point']}"/><label class="tip">*积分</label>
                {/if}
            </fieldset>
            <fieldset>
                <label>使用条件:</label>
                {if:$info['condition']==1}
                <label><input type="radio"   checked/>不限制</label>
                {else:}
                <label><input type="radio" checked />限制</label>
                <label id="areaBox">
                    {if:$info['use_type']==1}
                    满<input class='tiny' value="{$info['full_money']}"  disabled="disabled" type="text">元可用
                    {else:}
                    满<input class='tiny' value="{$info['full_point']}"  disabled="disabled" type="text">积分可用
                    {/if}
                </label>
                {/if}
            </fieldset>
            <fieldset>
                <label>有效期:</label>
                <input type="text"  class="normal" value="{$info['start_time']}"   disabled="disabled"/>——
                <input type="text"   class="normal"   value="{$info['end_time']}" disabled="disabled" />
            </fieldset>

            <fieldset>
                <label>说明:</label>
                <input   class="large" type="text"  name="description"  id="description"   value="{$info['description']}"  /><label class="tip">该优惠券使用的注意事项</label>
            </fieldset>
            <fieldset>
                <label>发放方式</label>
                <div class="box">
                    <label><input name="goods_sale"  id="goods_sale" value="1"  type="checkbox" {if:$info['goods_sale']==1}checked  disabled="disabled" {/if} onclick="sale_num_check();">当成商品销售</label>
                    <!--支持保价隐藏域-->
                    {if:$info['goods_sale']==0}
                    <span id='goodsBox' style='display:none'>
						 <input name="goods_sale_num" value="{$info['goods_sale_num']}"  id="goods_sale_num" class='tiny' pattern="int" alt="只允许填写数字" type="text" />件
					</span>
                    {else:}
                    <table>
                        <tr>
                            &nbsp;&nbsp;&nbsp;总数量：{if:$info['goods_sale_num']}{$info['goods_sale_num']}{else:}0{/if}
                        </tr>
                        <tr>
                            &nbsp;&nbsp;&nbsp;已发放：{if:$info['has_send']}{$info['has_send']}{else:}0{/if}
                        </tr>
                        <tr>
                            &nbsp;&nbsp;&nbsp;剩余数量：{if:$info['remain']}{$info['remain']}{else:}0{/if}
                        </tr>
                        <tr>
                            &nbsp;&nbsp;&nbsp;已失效：{if:$info['out_date']}{$info['out_date']}{else:}0{/if}
                        </tr>
                        <tr>
                            &nbsp;&nbsp;&nbsp; <input type="button" class="alt_btn" onclick="update_num();" value="修改数量" />
                        </tr>
                        <tr>
                            &nbsp;&nbsp;&nbsp; <input type="button" class="alt_btn" onclick="view_update_num();" value="变更记录" />
                        </tr>
                    </table>

                    {/if}
                </div>
                <div class="box">
                    <label><input name="prop_sale" id="prop_sale" value="1" type="checkbox" {if:$info['prop_sale']==1}checked  disabled="disabled" {/if} onclick="prop_sale_check();">作为奖品/奖励</label>
                    <!--支持保价隐藏域-->
                    <label id='propBox' style='display:none'><input type="radio"  checked/>不限制<br>
                        优惠券作为奖品奖励发放时，使用数量无法预估，故不进行限制，请确保做活动时，有充足的商品以供兑换<br>作为奖品/奖励，指该优惠券可以作为运营活动或奖励的奖品，发放给用户
                    </label>

                </div>
                {if:$info['goods_sale']==1&&$info['prop_sale']==1}
                <script>
                    window.onload=function(){
                        sale_num_check();
                        prop_sale_check();
                    }
                </script>
                {elseif:$info['goods_sale']==0&&$info['prop_sale']==1}
                <script>
                    window.onload=function(){
                        prop_sale_check();
                    }
                </script>
                {else:$info['goods_sale']==1&&$info['prop_sale']==0}
                <script>
                    window.onload=function(){
                        sale_num_check();
                    }
                </script>
                {/if}

            </fieldset>
            <fieldset>
                <label>总数量:</label>
                {if:$info['prop_sale']==1}
                <input  class="normal" id="total_quantity" type="text"  value="不限制" disabled="disabled"/>
                {/if}
                {if:$info['prop_sale']==0&& $info['goods_sale']==1}
                <input  class="normal" type="text" id="total_quantity" value="{$info['goods_sale_num']}" disabled="disabled"/>
                {/if}
            </fieldset>
            <div id="img_box" style="display: none" >
                <fieldset>
                    <div style="float: left">
                        <div class="image_display1" >
                            {if:$info['image1']}
                            <img src="{$info['image1']}" style="width:250px;height: 160px">
                                <input type="hidden" name="image1" id="image1" value="{$info['image1']}">
                            {/if}
                        </div>
                        <div data-role="fieldcontain" class="upload-box" style="width: 250px;height: 30px;margin-top: 10px;">
                            <input type="file" id="upload_img1" name="upload_img1"  value="上传"  />
                        </div>
                    </div>
                    <div style="float: left;margin-left: 50px;">
                        <div class="image_display2" >
                            {if:$info['image2']}
                            <img src="{$info['image2']}" style="width:250px;height: 160px">
                            <input type="hidden" name="image2"  id="image2" value="{$info['image2']}">
                            {/if}
                        </div>
                        <div data-role="fieldcontain" class="upload-box" style="width: 250px;height: 30px;margin-top: 10px;">
                            <input type="file" id="upload_img2" name="upload_img2"  value="上传"  />
                        </div>
                    </div>
                    <br>
                    <label>作为奖品/奖励发放时，系统提供默认的图片，可重新上传，尺寸为：160*160px 和 320*320px</label>
                </fieldset>
            </div>
        </div>
        <footer>
            <div class="submit_link">
                <input type="submit" class="alt_btn" value="确 定"/>
            </div>
        </footer>
    </form>
</article>
<script>
    $("form").submit(function (e) {
        var description_length = $('#description').val().length;
        if (description_length > 50) {
            alert('优惠券使用说明限制50个字符！');
            return false;
        }
        var prop_sale = $("#prop_sale").is(":checked");
        if(prop_sale){
            var image1 = $('#image1').val();
            var image2 = $('#image2').val();
            if (image1 == null || image1 == "" || image2 == null || image2 == "") {
                alert('作为奖品/奖励，图片必须上传！');
                return false;
            }
        }
        return true;
    });
    function sale_num_check() {
        $('#goodsBox').toggle();
        var goods_sale = $("#goods_sale").is(":checked");
        var prop_sale = $("#prop_sale").is(":checked");
        if (goods_sale == true) {
            if (prop_sale == true) {
                $("#total_quantity").attr("value", "不限制");//填充内容
            } else {
                var goods_sale_num = $("#goods_sale_num").attr("value");
                $("#total_quantity").attr("value", goods_sale_num);//填充内容
            }
        } else {
            if (prop_sale == true) {
                $("#total_quantity").attr("value", "不限制");//填充内容
            } else {
                $("#total_quantity").attr("value", '');//填充内容
            }
        }
    }
    function prop_sale_check() {
        $('#propBox').toggle();
        $('#img_box').toggle();
        var goods_sale = $("#goods_sale").is(":checked");
        var prop_sale = $("#prop_sale").is(":checked");
        if (prop_sale == false) {
            if (goods_sale == true) {
                var goods_sale_num = $("#goods_sale_num").attr("value");
                $("#total_quantity").attr("value", goods_sale_num);//填充内容
            } else {
                $("#total_quantity").attr("value", '');//填充内容
            }
        } else {
            $("#total_quantity").attr("value", "不限制");//填充内容
        }
    }

    $('#goods_sale_num').keyup(function () {
        var goods_sale_num = $("#goods_sale_num").attr("value");
        var prop_sale = $("#prop_sale").is(":checked");
        if (prop_sale == true) {
            $("#total_quantity").attr("value", '不限制');//填充内容
        } else {
            $("#total_quantity").attr("value", goods_sale_num);//填充内容
        }
    });

    function update_num()
    {

        var updateStatus = false;
        $.ajax({
            async: false,
            method: 'POST',
            url: "{url:/sellercoupon/check_coupon_num}",
            data: {coupon_id: {$id}},
            dataType: "json",
            success: function (res) {
                if (res.flag == 'fail') {
                    layer.msg(res.message);
                    return false;
                }
                updateStatus = true;
            },
        });
        if (updateStatus) {
            var url = '{url:/sellercoupon/update_num/coupon_id/$id}';
            art.dialog.open(url, {
                id: 'addSpecWin',
                title: '修改数量',
                okVal: '确定',

                ok: function (iframeWin, topWin) {
                    var formObject = iframeWin.document.forms['num_form'];
                    var me = this;
                    $.post(formObject.action, $(formObject).serialize(), function (json) {
                        if (json.flag == 'success') {
                            window.location.reload();
                            me.close();
                            return true;
                        }
                        else {
                            alert(json.message);
                            return false;
                        }
                    }, 'json');
                    return false;
                }
            });
        }

    }
    function view_update_num()
    {
            var url = '{url:/sellercoupon/coupon_change_log/coupon_id/$id}';
            art.dialog.open(url,{
                id:'addSpecWin',
                title:'变更记录',
                okVal:'确定',

            });
    }
    //照片异步上传
    $('#upload_img1').change(function () {  //此处用了change事件，当选择好图片打开，关闭窗口时触发此事件
        $.ajaxFileUpload({
            url: '{url:/sellercoupon/save_images}',   //处理图片的脚本路径
            type: 'post',       //提交的方式
            fileElementId: 'upload_img1',     //file控件ID
            secureuri: false,
            dataType: 'json',  //服务器返回的数据类型
            success: function (data) {  //提交成功后自动执行的处理函数
                $('.image_display1').empty();
                if(data.code=='success'){
                    ///此处效果是：当成功上传后会返回一个json数据，里面有url，取出url赋给img标签，然后追加到类里显示出图片
                    $('.image_display1').append('<img src="' + data.url + '" value="' + data.url + '" style="width:250px;height: 160px"><input type="hidden" name="image1" id="image1" value="'+data.url +'">');
                }
            }
        })
        return true;
    });
    //照片异步上传
    $('#upload_img2').change(function () {  //此处用了change事件，当选择好图片打开，关闭窗口时触发此事件
        $.ajaxFileUpload({
            url: '{url:/sellercoupon/save_images}',   //处理图片的脚本路径
            type: 'post',       //提交的方式
            fileElementId: 'upload_img2',     //file控件ID
            secureuri: false,
            dataType: 'json',  //服务器返回的数据类型
            success: function (data) {  //提交成功后自动执行的处理函数
                $('.image_display2').empty();
                if(data.code=='success'){
                    ///此处效果是：当成功上传后会返回一个json数据，里面有url，取出url赋给img标签，然后追加到类里显示出图片
                    $('.image_display2').append('<img src="' + data.url + '" value="' + data.url + '" style="width:250px;height: 160px"><input type="hidden" name="image2" id="image2" value="'+data.url+'">');
                }
            }
        })
        return true;
    });

</script>